package morenoapp.components.common;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import org.apache.poi.hssf.util.HSSFColor;

/**
 *
 * @author root
 */
public class OfficeColorsComboBox extends JComboBox {
    static Color[] colors;
    static {
        HSSFColor[] colorsHssf = new HSSFColor[]{
            new HSSFColor.AQUA(),
            new HSSFColor.AUTOMATIC(),
            new HSSFColor.BLACK(),
            new HSSFColor.BLUE(),
            new HSSFColor.BLUE_GREY(),
            new HSSFColor.BRIGHT_GREEN(),
            new HSSFColor.BROWN(),
            new HSSFColor.CORAL(),
            new HSSFColor.CORNFLOWER_BLUE(),
            new HSSFColor.DARK_BLUE(),
            new HSSFColor.DARK_GREEN(),
            new HSSFColor.DARK_RED(),
            new HSSFColor.DARK_TEAL(),
            new HSSFColor.DARK_YELLOW(),
//            new HSSFColor.GOLD(),
            new HSSFColor.GREEN(),
//            new HSSFColor.GREY_25_PERCENT(),
//            new HSSFColor.GREY_40_PERCENT(),
//            new HSSFColor.GREY_50_PERCENT(),
//            new HSSFColor.GREY_80_PERCENT(),
            new HSSFColor.INDIGO(),
            new HSSFColor.LAVENDER(),
            new HSSFColor.LEMON_CHIFFON(),
//            new HSSFColor.LIGHT_BLUE(),
//            new HSSFColor.LIGHT_CORNFLOWER_BLUE(),
//            new HSSFColor.LIGHT_GREEN(),
//            new HSSFColor.LIGHT_ORANGE(),
//            new HSSFColor.LIGHT_TURQUOISE(),
//            new HSSFColor.LIGHT_YELLOW(),
            new HSSFColor.LIME(),
            new HSSFColor.MAROON(),
            new HSSFColor.OLIVE_GREEN(),
            new HSSFColor.ORANGE(),
            new HSSFColor.ORCHID(),
            new HSSFColor.PALE_BLUE(),
            new HSSFColor.PINK(),
            new HSSFColor.PLUM(),
            new HSSFColor.RED(),
            new HSSFColor.ROSE(),
            new HSSFColor.ROYAL_BLUE(),
            new HSSFColor.SEA_GREEN(),
            new HSSFColor.SKY_BLUE(),
            new HSSFColor.TAN(),
            new HSSFColor.TEAL(),
            new HSSFColor.TURQUOISE(),
            new HSSFColor.VIOLET(),
            //new HSSFColor.WHITE(),
            //new HSSFColor.YELLOW()
        };
        colors = new Color[colorsHssf.length];
        for(int i=0;i<colorsHssf.length;i++){
            short[] triplet = colorsHssf[i].getTriplet();
            colors[i] = new Color(triplet[0],triplet[1],triplet[2]);
        }
    }
    static ListCellRenderer colorRenderer = new ColorListCellRenderer();

    static class ColorListCellRenderer extends DefaultListCellRenderer {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setText("\u2588\u2588");
            setForeground((Color)value);
            return this;
        }
    }

    /*
    static class ColorListCellRenderer extends JLabel implements ListCellRenderer {
        Color color = Color.BLACK;
        public ColorListCellRenderer() {
            super("   ");
        }

        @Override
        public void paint(Graphics g) {
            Rectangle r = getBounds();
            g.setColor(color);
            g.fillRoundRect(r.x, r.y, r.width, r.height, 5,5);
        }
        
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            this.color = (Color)value;
            return this;
        }
    };
 */

    public OfficeColorsComboBox() {
        super();

        setModel(new DefaultComboBoxModel(colors));
        setRenderer(colorRenderer);
    }

}
